<template>
  <div class="statsInfo">
    <el-container>
      <el-header>
        <header-item :item="tips"></header-item>
      </el-header>
      <el-main>
        <main-tools-item :toolsType="toolsType" :searchType="searchType" :defaultTime="defaultTime" @search='search'></main-tools-item>
        <!-- <div id="myChart" :style="{width: '100%', height: '300px', marginTop:'40px'}"></div> -->
        <el-table :data="dataList_f" v-loading="loading" height="120px" style="width: 100%;text-align:left;" :default-sort="{prop: 'time', order: 'descending'}"
          header-row-class-name="list_header" row-class-name="list_row" :row-style="{height:'60px'}" :cell-style="{padding:'0px'}">
          <template v-for="(item, index) in columns_f">
            <el-table-column :key="index" :prop="item.prop" :label="item.label" :align="item.align?item.align:'center'" :width="item.width"
              show-overflow-tooltip>
            </el-table-column>
          </template>
        </el-table>
        <el-table v-show="show" :data="dataList" v-loading="loading" height="calc(100% - 200px)" style="width: 100%;text-align:left;"
          :default-sort="{prop: 'time', order: 'descending'}" header-row-class-name="list_header" row-class-name="list_row"
          :row-style="{height:'60px'}" :cell-style="{padding:'0px'}">
          <template v-for="(item, index) in columns">
            <el-table-column :key="index" :prop="item.prop" :label="item.label" :align="item.align?item.align:'center'" :width="item.width"
              show-overflow-tooltip>
            </el-table-column>
          </template>
        </el-table>
      </el-main>
    </el-container>
  </div>
</template>

<script>
  import {
    get,
    post,
    pat,
    del,
    common,
    getRefresh
  } from "../../../../api/api";
  import headerItem from "./../../Commons/headerItem.vue";
  import mainToolsItem from "./../../Commons/mainToolsItem.vue";
  import mainSpareItem from "./../../Commons/mainSpareItem.vue";
  import mainDataListItem from "./../../Commons/mainDataListItem.vue";
  export default {
    components: {
      headerItem,
      mainToolsItem,
      mainSpareItem,
      mainDataListItem
    },
    data() {
      return {
        tips: "统计信息",
        toolsType: 2,
        searchType: 12,
        loading: false,
        show: false,
        defaultTime: {
          startTime: '',
          endTime: ''
        },
        columns_f: [{
            prop: 'date_time',
            label: '日期',
            width: '160px',
            align: 'center'
          },
          {
            prop: 'a',
            label: '商品订单累计总金额',
            width: '180px',
            align: 'center'
          },
          {
            prop: 'b',
            label: '商品订单累计RMB金额',
            width: '180px',
            align: 'center'
          },
          {
            prop: 'c',
            label: '商品累计总价',
            width: '140px',
            align: 'center',
          },
          {
            prop: 'd',
            label: '充值订单累计金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'e',
            label: '提现订单累计金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'f',
            label: '累计分红金额',
            width: '140',
            align: 'center'
          }, {
            prop: 'g',
            label: '累计分销金额',
            width: '140',
            align: 'center'
          }, {
            prop: 'c1',
            label: 'SVIP累计减免金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'i',
            label: '用户剩余余额',
            width: '160',
            align: 'center'
          }, {
            prop: 'h',
            label: '累计下发优惠券金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'c2',
            label: '累计使用优惠券金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'c3',
            label: '累计积分抵扣金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'tt',
            label: '累计投入',
            width: '220',
            align: 'center'
          }
        ],
        columns: [{
            prop: 'date_time',
            label: '日期',
            width: '160px',
            align: 'center'
          },
          {
            prop: 'a',
            label: '商品订单累计总金额',
            width: '180px',
            align: 'center'
          },
          {
            prop: 'b',
            label: '商品订单累计RMB金额',
            width: '180px',
            align: 'center'
          },
          {
            prop: 'c',
            label: '商品累计总价',
            width: '140px',
            align: 'center',
          },
          {
            prop: 'd',
            label: '充值订单累计金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'e',
            label: '提现订单累计金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'f',
            label: '累计分红金额',
            width: '140',
            align: 'center'
          }, {
            prop: 'g',
            label: '累计分销金额',
            width: '140',
            align: 'center'
          }, {
            prop: 'c1',
            label: 'SVIP累计减免金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'h',
            label: '累计下发优惠券金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'c2',
            label: '累计使用优惠券金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'c3',
            label: '累计积分抵扣金额',
            width: '160',
            align: 'center'
          }, {
            prop: 'tt',
            label: '累计投入',
            width: '220',
            align: 'center'
          }
        ],
        dataList: [],
        dataList_f: [],
        sels: [],
        param: {
          startTime: '',
          endTime: '',
        },
        page: {
          pageNo: 1,
          limit: 10,
          sizes: [10, 50, 100],
          total: -1
        },
        xAxisData: [],
        seriesUserinfo: [],
        seriesRechatge: [],
        seriesGoods: [],
        seriesWithdraw: [],
      };
    },
    methods: {
      drawLine() {
        return new Promise((resolve, reject) => {
          // 基于准备好的dom，初始化echarts实例
          let myChart = this.$echarts.init(document.getElementById('myChart'))
          // 绘制图表
          myChart.setOption({
            title: {
              text: ''
            },
            tooltip: {
              trigger: 'axis',
              axisPointer: { // 坐标轴指示器，坐标轴触发有效
                type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
              }
            },
            legend: {
              data: ['新增人数', '充值金额', '商品金额', '提现金额']
            },
            grid: {
              left: '3%',
              right: '4%',
              bottom: '3%',
              containLabel: true
            },
            xAxis: {
              type: 'category',
              data: this.xAxisData
            },
            yAxis: {
              type: 'value'
            },
            series: [{
              name: '新增人数',
              type: 'bar',
              data: this.seriesUserinfo
            }, {
              name: '充值金额',
              type: 'bar',
              data: this.seriesRechatge
            }, {
              name: '商品金额',
              type: 'bar',
              data: this.seriesGoods
            }, {
              name: '提现金额',
              type: 'bar',
              data: this.seriesWithdraw
            }]
          });
          resolve();
        });
      },
      //--------查询----------
      async search(val) {
        this.param ={}
        if (val.date.length == 0) {
          this.param.startTime = this.defaultTime.startTime;
          this.param.endTime = this.defaultTime.endTime;
        } else {
          this.param.startTime = "";
          this.param.endTime = "";
          this.param.startTime = val.date[0];
          this.param.endTime = val.date[1];
        }
        this.show = true;
        await this.getCountOrderList();
        // await this.drawLine();
      },
      batchDelete(val) {},
      //-------分页----------
      currentChange(val) {
        this.param.current = "";
        this.param.current = val
        this.getCountOrderList();
      },
      //获取list列表
      getCountTotalOrderList() {
        return new Promise((resolve, reject) => {
          post("/order/countTotalOrder", this.param).then(resdata => {
            let self = function () {
              this.$router.push({
                path: '/home'
              });
            }.bind(this);
            let error = function () {
              alert(resdata.msg)
            }.bind(this);
            let success = function () {
              if (resdata.code == 1) {
                this.dataList_f = resdata.data;
                this.dataList_f[0].date_time = "截止目前";
              }
            }.bind(this);
            common(self)(error)(success)(resdata);
            resolve();
          });
        });
      },
      //获取list列表
      getCountOrderList() {
        return new Promise((resolve, reject) => {
          post("/order/countOrder", this.param).then(resdata => {
            let self = function () {
              this.$router.push({
                path: '/home'
              });
            }.bind(this);
            let error = function () {
              alert(resdata.msg)
            }.bind(this);
            let success = function () {
              if (resdata.code == 1) {
                this.dataList = resdata.data;
              }
            }.bind(this);
            common(self)(error)(success)(resdata);
            resolve();
          });
        });
      },
    },
    async mounted() {
      await this.getCountTotalOrderList();
      // await this.drawLine();
    },
    watch: {}
  };

</script>

<style lang="scss">
  .statsInfo {
    background-color: white;
    font-size: 1.8rem;
    width: 100%;
    height: 100%;
    .el-container {
      height: 100%;
      .el-header,
      .el-footer {
        background-color: #F9FAFE;
        color: #333;
        text-align: center;
        line-height: 50px;
        height: 50px !important;
        .header-child {
          height: 50px;
          width: 100%;
          text-align: left;
          padding-left: 20px;
          background-color: #cbe9eb;
          border-bottom: 1px solid black;
          box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.5);
        }
      }
      .el-main {
        box-shadow: 0 5px 5px 0px rgba(0, 0, 0, 0.5); // margin: 10px 20px;
        margin: 10px;
        background-color: #fff;
        color: #333;
        text-align: center;
        height: 100%;
        .list_header th {
          background-color: #E8EFF9;
        }
        .list_row {
          height: 100px;
          td {
            padding: 0 !important;
            .cell {
              // max-height: 23px !important;
              overflow: hidden !important;
              .el-image {
                overflow: visible !important;
              }
            }
          }
        }
      }
    }
  }

</style>
